import {_decorator, Component, Node} from 'cc';
import {GameMainViewModel} from "db://assets/Scripts/MVC/game/main/GameMainViewModel";
import {GameMainUiState} from "db://assets/Scripts/MVC/game/main/GameMainUiState";
import {EventManager} from "db://assets/Scripts/Common/EventManager";
import {EventType} from "db://assets/Scripts/Common/EventType";
import {NodePath} from "db://assets/Scripts/Common/NodePath";

const {ccclass, property} = _decorator;

/**
 * 游戏主菜单界面逻辑
 */
@ccclass('GameMainController')
export class GameMainController extends Component {
    /**
     * 游戏主菜单业务逻辑
     */
    private viewModel: GameMainViewModel = new GameMainViewModel();
    /**
     * 游戏主菜单界面数据
     */
    private uiState: GameMainUiState = this.viewModel.uiState;

    onEnable() {
        // 注册触摸事件
        this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
    }

    onDisable() {
        // 取消注册触摸事件
        this.node.off(Node.EventType.TOUCH_START, this.onTouchStart, this);
    }

    start() {

    }

    update(deltaTime: number) {

    }

    /**
     * 当触摸节点时
     */
    private onTouchStart() {
        // 切换游戏状态
        EventManager.emit(EventType.MENU_VISIBILITY, NodePath.MAIN_MENU, false);
        EventManager.emit(EventType.MENU_VISIBILITY, NodePath.GAME_MENU, true);

        // 创建玩家
        EventManager.emit(EventType.CREATE_PLAYER);
    }
}